import Vue from 'vue'

const privacyPhone = Vue.filter('privacyPhone', (phone) => {
  if (phone) {
    let privacyPhone = phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
    return privacyPhone
  }
})
const formatDate = Vue.filter('formatDate', (time, format) => {
  let t = new Date(time)
  let timeFormat = i => {
    return (i < 10 ? '0' : '') + i
  }
  return format.replace(/yyyy|MM|dd|hh|mm|ss/g, a => {
    switch (a) {
      case 'yyyy':
        return timeFormat(t.getFullYear())
      case 'MM':
        return timeFormat(t.getMonth() + 1)
      case 'dd':
        return timeFormat(t.getDate())
      case 'hh':
        return timeFormat(t.getHours())
      case 'mm':
        return timeFormat(t.getMinutes())
      case 'ss':
        return timeFormat(t.getSeconds())
    }
  })
})
export default {
  privacyPhone,
  formatDate
}
